#include "net.h"

void usage(char* s)
{
	  printf("%s ser_ip ser_port>5000",s);
}
 
 //==========================================================
 int main(int argc, char** argv)
 {
    int fd;
	struct sockaddr_in soc;
    int port = PORT;
	//创建套
    if( (fd = socket(AF_INET, SOCK_DGRAM, 0))<0)
	{


		perror("socket");
        exit(1);

    }   
    if(argc != 3)
    {   
        usage(argv[0]);
        exit(1);
    }   

    port = atoi(argv[2]);
    if(port < 5000)
    {   
        usage(argv[0]);
        exit(1);
    }   

    //绑定结构体
    soc.sin_family = AF_INET;
    soc.sin_port = htons(PORT);
    if(inet_pton(AF_INET, argv[1], &soc.sin_addr) != 1)
    {   
        perror("inet_pton");
        exit(1);
    }   
    printf("udp client启动成功\n");


    //发送信息
    char buf[BUFSI];
    while(1)
    {   
        bzero(buf, BUFSIZ);
        if( fgets(buf, BUFSIZ-1, stdin) ==NULL) {
            perror("fgets");
            continue;
        }

        sendto(fd, buf, BUFSI-1, 0, (struct sockaddr*)&soc, sizeof(soc));
    }   
    close(fd);
    return 0;
}

